package com.CI.SearchCourse.Business
{
	import com.CI.SearchCourse.VO.SearchDirectVO;
	import com.CI.SearchCourse.VO.SearchOnlineVO;
	
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	public class SearchDelegate
	{
		protected var responder : Responder;
		
		public function SearchDelegate(responder : Responder)
		{
			this.responder = responder;
		}
		
		public function sendObject(obj : Object) : void
		{
			var params : Object = new Object();
			var service : HTTPService;
			var token : AsyncToken;
			var responder:mx.rpc.Responder;
			
			if(obj is SearchDirectVO)
			{
				var direct : SearchDirectVO = new SearchDirectVO();
				direct = obj as SearchDirectVO;
				params.action = 'search';
				params.name = direct.name;
				params.fromPrice = direct.fromPrice;
				params.toPrice = direct.toPrice;
				params.timeStart = direct.timeStart;
				params.situation = direct.situation;
				
				service = ServiceLocator.getInstance().getHTTPService("SearchCourseDirect");
		    	
		    	token = service.send(params);
				responder = new mx.rpc.Responder(Search_onResult, Search_onFault);
				token.addResponder(responder);	
			}
			else
			{
				var online : SearchOnlineVO = new SearchOnlineVO();
				online = obj as SearchOnlineVO;
				params.action = 'search';
				params.name = online.name;
				params.fromPrice = online.fromPrice;
				params.toPrice = online.toPrice;
				
				service = ServiceLocator.getInstance().getHTTPService("SearchCourseOnline");
		    	
		    	token = service.send(params);
				responder = new mx.rpc.Responder(Search_onResult, Search_onFault);
				token.addResponder(responder);
			}
		}
		
		protected function Search_onResult(event:ResultEvent) : void
		{
			
		}
		
		protected function Search_onFault(event:FaultEvent) : void
		{
		
		}
	}
}